//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "GeneralLinearLeastSquares.h"
using namespace Cephei::QL::Math;
#include <gen/QL/Math/Array.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::CGeneralLinearLeastSquares::CGeneralLinearLeastSquares (boost::shared_ptr<QuantLib::GeneralLinearLeastSquares>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGeneralLinearLeastSquares = NULL;
#endif
	_ppGeneralLinearLeastSquares = &childNative;
    
}
Cephei::QL::Math::CGeneralLinearLeastSquares::CGeneralLinearLeastSquares (QuantLib::GeneralLinearLeastSquares& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phGeneralLinearLeastSquares = NULL;
#endif
	_ppGeneralLinearLeastSquares = new boost::shared_ptr<QuantLib::GeneralLinearLeastSquares> (&childNative);
    
    _GeneralLinearLeastSquaresOwner = owner;
    
}

Cephei::QL::Math::CGeneralLinearLeastSquares::CGeneralLinearLeastSquares (CGeneralLinearLeastSquares^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGeneralLinearLeastSquares = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGeneralLinearLeastSquares = new boost::shared_ptr<QuantLib::GeneralLinearLeastSquares> (copy->GetShared());
        
    }
}
Cephei::QL::Math::CGeneralLinearLeastSquares::CGeneralLinearLeastSquares (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGeneralLinearLeastSquares = NULL;
#endif
	if (!t->IsSubclassOf(CGeneralLinearLeastSquares::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::CGeneralLinearLeastSquares::CGeneralLinearLeastSquares (QuantLib::Handle<QuantLib::GeneralLinearLeastSquares>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phGeneralLinearLeastSquares = &childNative;
	_ppGeneralLinearLeastSquares = &static_cast<boost::shared_ptr<QuantLib::GeneralLinearLeastSquares>>(childNative.currentLink());
    
    _GeneralLinearLeastSquaresOwner = owner;
}
Cephei::QL::Math::CGeneralLinearLeastSquares::CGeneralLinearLeastSquares (QuantLib::Handle<QuantLib::GeneralLinearLeastSquares> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phGeneralLinearLeastSquares = &childNative;
	_ppGeneralLinearLeastSquares = &static_cast<boost::shared_ptr<QuantLib::GeneralLinearLeastSquares>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::CGeneralLinearLeastSquares::CGeneralLinearLeastSquares (QuantLib::GeneralLinearLeastSquares childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGeneralLinearLeastSquares = NULL;
#endif
	_ppGeneralLinearLeastSquares = new boost::shared_ptr<QuantLib::GeneralLinearLeastSquares> (new QuantLib::GeneralLinearLeastSquares (childNative));
    
}
#endif

Cephei::QL::Math::CGeneralLinearLeastSquares::~CGeneralLinearLeastSquares ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppGeneralLinearLeastSquares != NULL)
    {
	    delete _ppGeneralLinearLeastSquares;
        _ppGeneralLinearLeastSquares = NULL;
    }
}
Cephei::QL::Math::CGeneralLinearLeastSquares::!CGeneralLinearLeastSquares ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppGeneralLinearLeastSquares != NULL)
    {
	    delete _ppGeneralLinearLeastSquares;
    }
}
QuantLib::GeneralLinearLeastSquares& Cephei::QL::Math::CGeneralLinearLeastSquares::GetReference ()
{
    if (_ppGeneralLinearLeastSquares == NULL) throw REFNEW NativeNullException ();
	return **_ppGeneralLinearLeastSquares;
}
boost::shared_ptr<QuantLib::GeneralLinearLeastSquares>& Cephei::QL::Math::CGeneralLinearLeastSquares::GetShared ()
{
    if (_ppGeneralLinearLeastSquares == NULL) throw REFNEW NativeNullException ();
	return *_ppGeneralLinearLeastSquares;
}
QuantLib::GeneralLinearLeastSquares* Cephei::QL::Math::CGeneralLinearLeastSquares::GetPointer ()
{
    if (_ppGeneralLinearLeastSquares == NULL) throw REFNEW NativeNullException ();
	return &**_ppGeneralLinearLeastSquares;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GeneralLinearLeastSquares>& Cephei::QL::Math::CGeneralLinearLeastSquares::GetHandle ()
{
	if (_phGeneralLinearLeastSquares == NULL)
	{
		_phGeneralLinearLeastSquares = new Handle<QuantLib::GeneralLinearLeastSquares> (*_ppGeneralLinearLeastSquares);
	}
	return *_phGeneralLinearLeastSquares;
}
#endif
bool Cephei::QL::Math::CGeneralLinearLeastSquares::HasNative () 
{
	return (_ppGeneralLinearLeastSquares != NULL);
}

Cephei::QL::Math::IArray^ Cephei::QL::Math::CGeneralLinearLeastSquares::A::get ()
{
    try
    {
    	QuantLib::Array& _rv = (QuantLib::Array&)(*_ppGeneralLinearLeastSquares)->a ( );   
        Cephei::QL::Math::CArray^ _nrv = REFNEW Cephei::QL::Math::CArray (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::IArray^ Cephei::QL::Math::CGeneralLinearLeastSquares::Coefficients::get ()
{
    try
    {
    	QuantLib::Array& _rv = (QuantLib::Array&)(*_ppGeneralLinearLeastSquares)->coefficients ( );   
        Cephei::QL::Math::CArray^ _nrv = REFNEW Cephei::QL::Math::CArray (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Math::CGeneralLinearLeastSquares::Dim::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppGeneralLinearLeastSquares)->dim ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::IArray^ Cephei::QL::Math::CGeneralLinearLeastSquares::Error::get ()
{
    try
    {
    	QuantLib::Array& _rv = (QuantLib::Array&)(*_ppGeneralLinearLeastSquares)->error ( );   
        Cephei::QL::Math::CArray^ _nrv = REFNEW Cephei::QL::Math::CArray (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::IArray^ Cephei::QL::Math::CGeneralLinearLeastSquares::Residuals::get ()
{
    try
    {
    	QuantLib::Array& _rv = (QuantLib::Array&)(*_ppGeneralLinearLeastSquares)->residuals ( );   
        Cephei::QL::Math::CArray^ _nrv = REFNEW Cephei::QL::Math::CArray (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Math::CGeneralLinearLeastSquares::Size::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppGeneralLinearLeastSquares)->size ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::IArray^ Cephei::QL::Math::CGeneralLinearLeastSquares::StandardErrors::get ()
{
    try
    {
    	QuantLib::Array& _rv = (QuantLib::Array&)(*_ppGeneralLinearLeastSquares)->standardErrors ( );   
        Cephei::QL::Math::CArray^ _nrv = REFNEW Cephei::QL::Math::CArray (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

